<template>
  <div class="app-container">
    <el-form ref="formRef" :model="form" :rules="rules" label-width="150px" label-position="top">

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入姓名" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="身份证号码" prop="idCard">
            <el-input v-model="form.idCard" placeholder="请输入身份证号码" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="年龄" prop="age">
            <el-input v-model.number="form.age" placeholder="请输入年龄" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="性别" prop="gender">
            <el-input v-model.number="form.gender" placeholder="请输入性别" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="民族" prop="ethnic">
            <el-input v-model="form.ethnic" placeholder="请输入民族" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="文化程度" prop="educationLevel">
            <el-input v-model="form.educationLevel" placeholder="请输入文化程度" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="工龄" prop="workYears">
            <el-input v-model.number="form.workYears" placeholder="请输入工龄" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="所属地区" prop="parkId">
            <el-input v-model.number="form.parkId" placeholder="请输入所属地区" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="联系电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入联系电话" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="工种" prop="jobTypeId">
            <el-input v-model.number="form.jobTypeId" placeholder="请输入工种" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="行业" prop="industryId">
            <el-input v-model.number="form.industryId" placeholder="请输入行业" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="家庭地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入家庭地址" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="申报时间" prop="applyTime">
            <el-date-picker clearable
                            v-model="form.applyTime"
                            type="date"
                            value-format="YYYY-MM-DD"
                            placeholder="请选择申报时间"
                            style="width: 100%"
            />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="单位名称" prop="unitName">
            <el-input v-model="form.unitName" placeholder="请输入单位名称" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="机构代码" prop="socialCreditCode">
            <el-input v-model="form.socialCreditCode" placeholder="请输入机构代码" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="审核状态" prop="auditStatus">
            <el-input v-model.number="form.auditStatus" placeholder="请输入审核状态" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="上传文件路径" prop="uploadFile">
            <image-upload v-model="form.uploadFile"/>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="审核时间" prop="auditTime">
            <el-date-picker clearable
                            v-model="form.auditTime"
                            type="datetime"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            placeholder="请选择审核时间"
                            style="width: 100%"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="是否单位" prop="isUnit">
            <el-input v-model.number="form.isUnit" placeholder="请输入是否单位" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { addDataReview } from "@/api/health/dataReview"

const form = ref({
  name: '',
  idCard: '',
  age: null,
  gender: null,
  ethnic: '',
  educationLevel: '',
  workYears: null,
  parkId: null,
  phone: '',
  jobTypeId: null,
  industryId: null,
  address: '',
  applyTime: null,
  auditStatus: null,
  unitName: '',
  socialCreditCode: '',
  uploadFile: '',
  auditTime: null,
  remark: '',
  isUnit: null
})

const rules = reactive({
  name: [
    { required: true, message: "姓名不能为空", trigger: "blur" }
  ],
  idCard: [
    { required: true, message: "身份证号码不能为空", trigger: "blur" }
  ],
  isUnit: [
    { required: true, message: "是否单位不能为空", trigger: "blur" }
  ]
})

const formRef = ref(null)

// 提交表单
function submitForm() {
  formRef.value.validate(valid => {
    if (valid) {
      addDataReview(form.value).then(response => {
        ElMessage.success("新增成功")
        resetForm()
      })
    } else {
      return false
    }
  })
}

// 取消
function cancel() {
  resetForm()
  // 可选：跳转回列表页
  // router.push({ path: '/health/dataReview' })
}

// 重置表单
function resetForm() {
  for (let key in form.value) {
    form.value[key] = ''
  }
  form.value.age = null
  form.value.gender = null
  form.value.auditStatus = null
  form.value.isUnit = null
}
</script>

<style scoped>
.app-container {
  padding: 20px;
  background-color: #fff;
  border-radius: 4px;
}
</style>
